/**
 * 
 */
package spitfire.ksim.node;

import spitfire.ksim.network.KNetAddress;
import spitfire.ksim.network.KNetwork;
import spitfire.ksim.network.KPacket;
import spitfire.ksim.network.KWirelessNetworkModule;
import spitfire.ksim.util.TPoint;

/**
 * {@link KWirelessNetworkModule} implementation for nodes in spitfire simulator.
 * 
 * @author Adam
 *
 */
public class KNodeNetworkModule extends KWirelessNetworkModule {

	private final KNode hostNode;
	
	public KNodeNetworkModule(KNode node, KNetwork network, double radioRange) {
		super(network, radioRange);
		hostNode = node;
	}
	
	public KNode getNode() {
		return hostNode;
	}

	@Override
	public TPoint getLocation() {
		return hostNode.getLocation();
	}

	@Override
	public void recv(KPacket packet) {
		if (packet.getDstAddr().equals(getNetAddr())
				|| packet.getDstAddr() == KNetAddress.BROADCAST_ADDR) {
			// accept the packet
			hostNode.onPacketRecv(packet.getSrcAddr(), packet.getPayload());
		} else {
			// not for me, discard the packet(do nothing)
		}
	}
}
